import TableData from "@/components/public/el-table-pagination"; //主页面列表

import formJs from "./regexDetail.js"; //新增弹框配置项
import CustomDialog from "@/components/environmentalMonitorManage/testingRecord/index.vue";
import {
    safetyMonitorManageStatusType
} from "@/utils/config"; //配置项
import {
    getGantryCraneDetailsDataListByDeviceNum, //龙门吊详情
    getBridgemachinePageListNum, //架桥机
    getTowercranePageListNum, //塔吊
    getCradledataPageListNum, //挂篮
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "statusNum",
        "currentRow",
        "status"
    ],
    data() {
        return {
            visible: "",
            loading: false,
            table_config: null, //formJs.table_config
            displaySwitching: null,
            isLock: false,
            dialogHeight: null,
            tableData: [],
            currentDetail: null,
            listLoading: true,
            rowDetail: null,

            tableTitle: null,
            flagNum: null,
            keyType: null,
            closeType: null,
            queryCriteriaData: {}, //分页
            getList: {
                keyType: "", // 工程名称, //选择的设备名称的设备编号
                page: 1, //当前页码
                pageSize: 20 //每页显示数据
            },
            currentLine: null, //本行数据
            title: null, //标题
            isShow: false, //是否显示弹框
            currentDetial: null,
            btnWarn: null

        };
    },
    components: {
        TableData,
        CustomDialog


    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetial = newVal;
                    console.log(this.currentDetial.deviceNum);
                    // jqjRecordId
                    this.getList.keyType = newVal.deviceNum;
                    // if (this.statusNum != 1) {

                    // }
                }
            },
            immediate: true,
        },
        status: {
            handler(newVal) {
                if (newVal) {
                    if (newVal == 1) { //安全龙门吊
                        this.table_config = formJs.table_config1
                        this.title = "龙门吊监测"
                        this.btnWarn = [{
                                index: 4,
                                name: 'mainhookStatus'
                            }, {
                                index: 6,
                                name: 'subsidiaryhookStatus'
                            },
                            {
                                index: 8,
                                name: 'windspeedAlarm'
                            }, {
                                index: 10,
                                name: 'legDeviationAlarm'
                            },
                        ]
                    } else if (newVal == 2) { //安全架桥机
                        this.table_config = formJs.table_config2
                        this.title = "架桥机监测"
                        this.btnWarn = [{
                                index: 4,
                                name: 'crane1LoadStatus'
                            },
                            {
                                index: 5,
                                name: 'crane1Brake1Status'
                            }, {
                                index: 6,
                                name: 'windSlipStatus'
                            }, {
                                index: 7,
                                name: 'cableStatus'
                            }, {
                                index: 8,
                                name: 'crane2LoadStatus'
                            }, {
                                index: 9,
                                name: 'crane2Brake1Status'
                            }, {
                                index: 10,
                                name: 'crane2Brake2Status'
                            },
                        ];
                    } else if (newVal == 3) { //安全塔吊
                        this.table_config = formJs.table_config3
                        this.title = "塔吊监测"
                        this.btnWarn = [{
                            index: 5,
                            name: 'mainStatus1'
                        }, {
                            index: 6,
                            name: 'auxStatus1'
                        }, {
                            index: 7,
                            name: 'mainStatus2'
                        }, {
                            index: 8,
                            name: 'auxStatus2'
                        }, ]
                    } else if (newVal == 4) { //安全挂篮
                        this.title = "挂篮监测"
                        this.table_config = formJs.table_config4
                        this.btnWarn = [{
                                index: 2,
                                name: 'rebar1IsOverweight'
                            }, {
                                index: 3,
                                name: 'rebar2IsOverweight'
                            }, {
                                index: 4,
                                name: 'rebar3IsOverweight'
                            },
                            {
                                index: 5,
                                name: 'rebar4IsOverweight'
                            },
                        ]
                    }
                }
                this.btnWarn.map((item => {
                    this.table_config.thead[item.index]["callback"] = function (rowData) {
                        let data = safetyMonitorManageStatusType[rowData[item.name]];
                        if (data) {
                            return data.label;
                        }
                    };
                    this.table_config.thead[item.index]["specialClass"] = function (rowData) {
                        let data = safetyMonitorManageStatusType[rowData[item.name]];
                        if (data) {
                            return data.className;
                        }
                    };
                }))
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        this.btnShow = true

        if (this.statusNum == 7) { //查看
            this.getDetail(this.getList)

        }
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        closeDialog1() {

            this.isShow = false;
            // this.$emit("close0");
        },
        refreshList() { //刷新列表
            this.$nextTick(() => {
                this.getDetail(this.getList);
            })
        },
        // 点击查看
        yj_viewForm(row, label) {

            if (label == "设备编号") {
                this.statusNum = 7
                this.currentLine = row;
                this.isShow = true;
            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentLine = val

        },
        // 详情
        getDetail(obj) {
            var str;
            if (this.status == 1) { //龙门吊
                str = getGantryCraneDetailsDataListByDeviceNum
            } else if (this.status == 2) { //架桥机 2
                str = getBridgemachinePageListNum
            } else if (this.status == 3) { //塔吊 3
                str = getTowercranePageListNum

            } else if (this.status == 4) { //挂篮  4
                str = getCradledataPageListNum
            }
            this.loading = true;
            str(obj).then((res) => {
                if (res.errcode == 0) {
                    var data = res.data.pageInfo.list;
                    console.log(454545, data);
                    this.tableData = data;
                    this.loading = false;
                    this.listLoading = false;

                    this.queryCriteriaData = res.data.pageInfo;
                } else {
                    this.loading = false;
                    this.$message.error(res.msg);
                }
            });
        },
    },
};